const { parseToken } = require("../tools/token");


function testPwd(req, res, next) {

    // 接收参数
    const { user, pass, newPwd } = req.body;
    if (!user || !pass || !newPwd) {
        return res.send({ s: 0, 'txt': '参数错误' })
    }

    next()
}


function testToken(req, res, next) {

    // 拿到token   
    const token = req.headers.authorization;
    // token解密
    parseToken(token).then(data => {
        if (!data.status) {
            return res.send({ s: 0, 'txt': 'token验证失败' })
        }
        else {
            // const {token} = data ;
            // token 和用户名密码进行校验

            next()
        }
    })

}


module.exports.testPwd = testPwd;
module.exports.testToken = testToken;